package com.tyg.util;

public class ResultCode<T> {
    private int code; //响应状态码
    private String msg ;
    private String status ;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public ResultCode(int code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public ResultCode() {
        super();
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResultCode(T data) {
        this.data = data;
    }

    public static ResultCode<?> success() {
        ResultCode<?> result = new ResultCode<>();
        result.setCode(200);
        result.setMsg("成功");
        return result;
    }

    public static <T> ResultCode<T> success(T data) {
        ResultCode<T> result = new ResultCode<>(data);
        result.setCode(200);
        result.setMsg("成功");
        return result;
    }


    public static ResultCode<?> error(int code, String msg) {
        ResultCode<?> result = new ResultCode();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    public static <T> ResultCode<T> error(T data) {
        ResultCode<T> result = new ResultCode<>(data);
        result.setCode(900);
        result.setMsg("失败");
        return result;
    }
}
